public class Rotate {
    // 轮转数组
    // https://leetcode.cn/problems/rotate-array/?envType=study-plan-v2&envId=top-100-liked
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        k %= len;
        reverse(nums, 0, len-k-1);
        reverse(nums, len-k,len-1);
        reverse(nums, 0, len-1);
    }

    private void reverse(int[] nums, int left, int right) {
        while (left < right) {
            int tmp = nums[left];
            nums[left++] = nums[right];
            nums[right--] = tmp;
        }
    }

}
